home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / Shaders / TexturingAndModeling:AProceduralApproach / KMShaders / KMWindyWave.sl < prev    next >
Encoding:
Text File  |  1995-03-22  |  1.7 KB  |  68 lines

  1. /*
  2.  * windywave.sl -- displacement shader for water waves modulated by a
  3.  *                 wind field.
  4.  *
  5.  * DESCRIPTION:
  6.  *    Two octaves of noise make waves appropriate for a lake or other large
  7.  *    body of water.  This displacement is modulated by another turbulent
  8.  *    term which accounts for wind variations across the lake.
  9.  *
  10.  * PARAMETERS:
  11.  *    Km - overall amplitude scale for the waves
  12.  *    txtscale - overall frequency scaling for the waves
  13.  *    windfreq - lowest frequency of the wind variations
  14.  *    windamp - amplitude of the wind variation
  15.  *    minwind - minimum wind value
  16.  *
  17.  * ANTIALIASING:
  18.  *    None.
  19.  *
  20.  * AUTHOR:
  21.  *    C language version by F. Kenton Musgrave
  22.  *    Translation to Shading Language by Larry Gritz.
  23.  *
  24.  * REFERENCES:
  25.  *    _Texturing and Modeling: A Procedural Approach_, by David S. Ebert, ed.,
  26.  *    F. Kenton Musgrave, Darwyn Peachey, Ken Perlin, and Steven Worley.
  27.  *    Academic Press, 1994.  ISBN 0-12-228760-6.
  28.  *
  29.  * HISTORY:
  30.  *    ??? - original C language version by Ken Musgrave
  31.  *    Apr 94 - translation to Shading Language by L. Gritz
  32.  *
  33.  * this file last updated 18 Apr 1994
  34.  */
  35.  
  36.  
  37. #define snoise(Pt) (2*noise(Pt) - 1)
  38.  
  39.  
  40.  
  41. displacement
  42. KMWindyWave (float Km = 0.1;
  43.          float txtscale = 1;
  44.          float windfreq = 0.5;
  45.          float windamp = 1;
  46.          float minwind = 0.3)
  47. {
  48.   float offset;
  49.   point PP;
  50.   float wind;
  51.   float turb, a, i;
  52.  
  53.   PP = txtscale * windfreq * transform ("shader", P);
  54.  
  55.   offset = Km * (snoise(PP) + 0.5 * snoise(2*PP));
  56.  
  57.   turb = 0;  a = 1;  PP *= 8;
  58.   for (i = 0;  i < 4;  i += 1) {
  59.       turb += abs (a * snoise(PP));
  60.       PP *= 2;
  61.       a /= 2;
  62.     }
  63.   wind = minwind + windamp * turb;
  64.  
  65. /*  P += wind * offset * normalize(N); */
  66.   N = calculatenormal (P+wind * offset * normalize(N));
  67. }
  68.